<template>
  <div>
    <!--面包屑导航区-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--卡片视图区域-->
    <el-card>
      <!--用户列表区域-->
      <el-table :data="rightsList" border stripe>
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column label="权限名称" prop="name"></el-table-column>
        <el-table-column label="路径" prop="path"></el-table-column>
        <el-table-column label="权限等级" prop="level">
          <template v-slot="scope">
            <el-tag v-if="scope.row.level === 0">一级</el-tag>
            <el-tag type="info" v-else-if="scope.row.level === 1">二级</el-tag>
            <el-tag type="warning" v-else>三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <!--分页区域-->
      <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="queryInfo.pagenum"
                     :page-sizes="[1, 2, 5, 10]"
                     :page-size="queryInfo.pagesize"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>

    </el-card>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        // 获取权限列表的参数对象
        queryInfo: {
          pagenum: 1,
          pagesize: 5
        },
        total: 0,
        // 权限列表
        rightsList: []
      }
    },
    created() {
      // 获取所有权限数据
      this.getRightsList()
    },
    methods: {
      // 获取权限列表
      async getRightsList() {
        const { data: res } = await this.$http.get('GetMenusAll', { params: this.queryInfo })
        if (!res.state) {
          this.$message.error(res.text)
        }
        this.rightsList = res.data.data
        this.total = res.data.total
      },
      // 监听pagesize改变的事件
      handleSizeChange(newSize) {
        this.queryInfo.pagesize = newSize
        this.getRightsList()
      },
      // 监听页码值 改变的事件
      handleCurrentChange(newPage) {
        this.queryInfo.pagenum = newPage
        this.getRightsList()
      }
    }
  }
</script>

<style lang="less" scoped>
</style>
